
//
//  XiaoJianPanXunLianViewController.swift
//  ZHM
//
//  Created by zzddongge on 16/7/22.
//  Copyright © 2016年 zzd. All rights reserved.
//

import UIKit

class XiaoJianPanXunLianViewController: UIViewController,SheZhiViewControllerDelegate {

    
    let screenWidth = UIScreen.main.bounds.width
    let screenHeight = UIScreen.main.bounds.height
    var navigationHeight:CGFloat?
    var xuanXiangBtn:UIButton?
    var woZhiDaoLeBtn:UIButton?
    
    //创建小键盘训练说明,让读者一目了然
    var xiaoJianPanXunLianDescription:UILabel?
    
    //定义训练时间UILabel对象
    var xunLianShiJian:UILabel?
    //定义训练分钟值UILabel对象
    var xunLianShiJianZhi:UILabel?
    //定义分钟UILabel对象
    var fenZhong:UILabel?
    
    
    //定义训练模式UILabel对象
    var xunLianMoShi:UILabel?
    //定义训练模式值UILabel对象
    var xunLianMoShiZhi:UILabel?
    //定义模式UILabel对象
    var moShi:UILabel?
    
    override func viewDidLoad() {
        fengZhuangViewDidLoad()
    }
    
    /*
        作者:张振东
        日期:20176-09-08
        功能:封装viewDidLoad函数中的初始化label对象
     */
    func fengZhuangUiLabelAttributes(_ label:UILabel){
        switch label {
        case xiaoJianPanXunLianDescription!:
            //初始化小键盘训练说明
            label.layer.cornerRadius = 10
            label.clipsToBounds = true
            label.backgroundColor = UIColor(red: 232/255.0,green:232/255.0,blue:232/255.0,alpha:1)
            label.text = "本课程帮助您熟悉小键盘,您可以随时更改每组显示数字的个数.单击'开始'按钮进行训练时,按'/'、'*'或者空格键可以更换下一组数字."
            label.font = UIFont.systemFont(ofSize: 17)
            label.layer.borderWidth = 1
            label.layer.borderColor = UIColor(red: 232/255.0,green:232/255.0,blue:232/255.0,alpha:1).cgColor
            label.numberOfLines = 0
            self.automaticallyAdjustsScrollViewInsets = false
        case xunLianShiJian!:
            label.text = "训练时间:"
            label.font = UIFont.systemFont(ofSize: 16)
            
        case xunLianShiJianZhi!:
            label.textAlignment = .center
            label.font = UIFont.systemFont(ofSize: 16)
            label.text = "2"
        case fenZhong!:
           
            label.text = "分钟"
            label.font = UIFont.systemFont(ofSize: 16)
        case xunLianMoShi!:
            
            label.font = UIFont.systemFont(ofSize: 16)
            label.text = "训练模式:"
            
        case xunLianMoShiZhi!:
            label.textAlignment = .center
            label.font = UIFont.systemFont(ofSize: 16)
            label.text = "计时"
        case moShi!:
            
            label.font = UIFont.systemFont(ofSize: 16)
            label.text = "模式"
        default:
            print("初始化完毕")
        }
    
    }
    
    
    func chuanDiMoShiAndFenZhong(_ xuanZhongDeMoShiZhi: String, xuanZhongFenZhongZhi: String) {
        print(xuanZhongDeMoShiZhi)
        print(xuanZhongFenZhongZhi)
        self.xunLianMoShiZhi?.text = xuanZhongDeMoShiZhi
        self.xunLianShiJianZhi?.text = xuanZhongFenZhongZhi
        
    }
    
    /*
        作者:张振东
        日期:2017-09-08
        功能:封装viewDidLoad函数
     */
    func fengZhuangViewDidLoad(){
        self.title = "小键盘训练"
        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white,NSFontAttributeName:UIFont(name: "STHeitiSC-Medium", size: 20.0)!]
        self.view.backgroundColor = UIColor(red: 246,green: 246,blue: 246,alpha: 1)
        let leftBarButton = UIButton(frame:CGRect(x: 0,y: 0,width: 20,height: 20))
        leftBarButton.setBackgroundImage(UIImage(named: "fanhui"), for: UIControlState())
        leftBarButton.addTarget(self, action: #selector(backToPrevious), for: .touchUpInside)
        let leftBarButtonItem = UIBarButtonItem(customView: leftBarButton)
        self.navigationItem.leftBarButtonItems = [leftBarButtonItem]
        
        //获取导航栏的高度
        navigationHeight = self.navigationController?.navigationBar.bounds.size.height
        
        //初始化小键盘训练说明
        xiaoJianPanXunLianDescription = UILabel(frame:CGRect(x: 10,y: navigationHeight!+70,width: screenWidth-20,height: 100))
        fengZhuangUiLabelAttributes(xiaoJianPanXunLianDescription!)
        //初始化训练时间UILabel对象
        xunLianShiJian = UILabel(frame:CGRect(x: screenWidth/2-70,y: navigationHeight!+70+100+50,width: 70,height: 25))
        fengZhuangUiLabelAttributes(xunLianShiJian!)
        
        //初始化训练时间值UILabel对象
        xunLianShiJianZhi = UILabel(frame:CGRect(x: screenWidth/2+15,y: navigationHeight!+70+100+50,width: 30,height: 25))
        fengZhuangUiLabelAttributes(xunLianShiJianZhi!)
        
        //初始化分钟UILabel对象
        fenZhong = UILabel(frame:CGRect(x: screenWidth/2+50,y: navigationHeight!+70+100+50,width: 40,height: 25))
        fengZhuangUiLabelAttributes(fenZhong!)
        
        //初始化训练模式UIlabel对象
        xunLianMoShi = UILabel(frame:CGRect(x: screenWidth/2-70,y: navigationHeight!+70+100+50+25+20,width: 70,height: 25))
        fengZhuangUiLabelAttributes(xunLianMoShi!)
        
        //初始化训练模式值UILabel对象
        xunLianMoShiZhi = UILabel(frame:CGRect(x: screenWidth/2+10,y: navigationHeight!+70+100+50+25+20,width: 40,height: 25))
        fengZhuangUiLabelAttributes(xunLianMoShiZhi!)
        
        //初始化训练模式值UILabel对象
        moShi = UILabel(frame:CGRect(x: screenWidth/2+50,y: navigationHeight!+70+100+50+25+20,width: 40,height: 25))
        fengZhuangUiLabelAttributes(moShi!)
        
        //初始化我知道了按钮
        woZhiDaoLeBtn = UIButton(frame:CGRect(x: 10,y: screenHeight-60,width: screenWidth-20,height: 40))
        woZhiDaoLeBtn?.backgroundColor = UIColor(red: 231/255,green: 76/255,blue: 60/255,alpha: 1)
        woZhiDaoLeBtn?.setTitle("开始", for: UIControlState())
        woZhiDaoLeBtn?.layer.cornerRadius = 10
        woZhiDaoLeBtn?.setTitleColor(UIColor.white, for: UIControlState())
        
        //初始化选项按钮
        xuanXiangBtn = UIButton(frame:CGRect(x: 10,y: screenHeight-110,width: screenWidth-20,height: 40))
        xuanXiangBtn?.backgroundColor = UIColor(red: 231/255,green: 76/255,blue: 60/255,alpha: 1)
        xuanXiangBtn?.setTitle("选项", for: UIControlState())
        xuanXiangBtn?.layer.cornerRadius = 10
        xuanXiangBtn?.setTitleColor(UIColor.white, for: UIControlState())
        
        self.view.addSubview(xiaoJianPanXunLianDescription!)
        self.view.addSubview(xunLianShiJian!)
        self.view.addSubview(xunLianShiJianZhi!)
        self.view.addSubview(fenZhong!)
        self.view.addSubview(xunLianMoShi!)
        self.view.addSubview(xunLianMoShiZhi!)
        self.view.addSubview(moShi!)
        self.view.addSubview(xuanXiangBtn!)
        self.view.addSubview(woZhiDaoLeBtn!)
        
        //给按钮"我知道了"添加点击事件
        woZhiDaoLeBtn?.addTarget(self, action: #selector(tiaoZhuanZhiXunLianMode), for: .touchUpInside)
        xuanXiangBtn?.addTarget(self, action: #selector(tiaoZhuanZhiSheZhiXuanXiang), for: .touchUpInside)
        super.viewDidLoad()

    }
    
    override func viewWillAppear(_ animated: Bool) {
        self.title = "小键盘训练"
        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white,NSFontAttributeName:UIFont(name: "STHeitiSC-Medium", size: 20.0)!]
    }
 
    //该方法开始练习界面
    func tiaoZhuanZhiXunLianMode(){
        let xiaoKeyboardLianXiViewController = XiaoKeyboardLianXiViewController()
        xiaoKeyboardLianXiViewController.moShiLeiBie = self.xunLianMoShiZhi?.text
        xiaoKeyboardLianXiViewController.fenZhongZhi = self.xunLianShiJianZhi?.text
        self.navigationController?.pushViewController(xiaoKeyboardLianXiViewController, animated: true)
        
//        let xiaoJianPanExerciseViewController = XiaoJianPanExerciseViewController()
//        xiaoJianPanExerciseViewController.moShiLeiBie = self.xunLianMoShiZhi?.text
//        xiaoJianPanExerciseViewController.fenZhongZhi = self.xunLianShiJianZhi?.text
//        self.navigationController?.pushViewController(xiaoJianPanExerciseViewController, animated: true)
    }
    
    //该方法点击选项跳转到设置界面
    func tiaoZhuanZhiSheZhiXuanXiang(){
        let sheZhiViewController = SheZhiViewController()
        sheZhiViewController.delegate = self
        self.navigationController?.pushViewController(sheZhiViewController, animated: true)
    }
    
    
    //返回到上一个页面
    func backToPrevious(){
        self.navigationController?.popViewController(animated: true)
    }
    


}
